<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>注册</title>
		<meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;" />
		<!-- <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
		<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
		<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> -->
		<link rel="stylesheet" href="../lib/bootstrap.min.css">
		
		
	</head>
	<body>
		<style type="text/css">
			.container{ padding-top: 15px;}
			.col-xs-3 { line-height: 35px; color: #999; }
			.col-xs-8,.col-xs-4{ margin-left: 0; padding-left: 0;}
			.row{ padding-top: 8px; padding-bottom: 8px; border-bottom:1px #EAEAEA solid ;}
			.form-control{ color: #333 !important; border: none;}
			.yanzhengma{ line-height: 30px; padding: 0px 8px; border: 1px #EAEAEA solid; color: #000; z-index: 999; border-radius: 3px;
			 position: absolute; right: 25px; top: 10px;}
			 
			.form-control{ background: none !important;}
			.form-control:focus {border-color: #66afe9; outline: 0;-webkit-box-shadow: inset 0px 0px 5px #FFFFFF}	
			 .go{background: #ffa328; font-weight: 600; color: #FFFFFF; text-align: center; font-size: 1.6rem; padding: 10px 0; margin-top: 20px; border-radius: 5px;}
		</style>
		<div class="container">
			<div class="row">
				<div class="col-xs-3 col-xs-offset-1">手机号</div>
				<div class="col-xs-8"><input type="text" class="form-control" name="" id="shoujihao" placeholder="请输入手机号"/></div>
			</div>
			<div class="row" style="position: relative;">
				<div class=""><input type="button" class="yanzhengma" value="验证码"> </div>
				<div class="col-xs-3 col-xs-offset-1">验证码</div>
				<div class="col-xs-4"><input type="text" class="form-control" name="" id="yanzhengma" value="" placeholder="请输入验证码" /></div>
			</div>
			<div class="row">
				<div class="col-xs-3 col-xs-offset-1">密码</div>
				<div class="col-xs-8"><input type="password" class="form-control" name="" id="password" value="" placeholder="请输入密码" /></div>
			</div>
			<div class="row">
				<div class="col-xs-3 col-xs-offset-1">确认密码</div>
				<div class="col-xs-8"><input type="password" class="form-control" name="" id="password2" value="" placeholder="请再次输入密码" /></div>
			</div>
			<div class="row">
				<div class="col-xs-3 col-xs-offset-1">推荐码</div>
				<div class="col-xs-8"><input type="text" class="form-control" name="" id="fphone" value="" placeholder="输入推荐码/推荐人手机号码" /></div>
			</div>
			<!-- <div class="row">
				<div class="col-xs-3 col-xs-offset-1">推荐码</div>
				<div class="col-xs-8"><input type="text" class="form-control" name="" id="fid" value="" placeholder="输入推荐码" /></div>
			</div> -->
			
			<div class="go">注册</div>
		</div>
		
		<script type="text/javascript" src="../lib/jquery.min.js"></script>
		<script type="text/javascript" src="../lib/bootstrap.min.js"></script>
		<script type="text/javascript" src="../lib/vue.min.js"></script>
		<script type="text/javascript" src="../lib/common.js"></script>
		<script src="../lib/md5.js" type="text/javascript"></script>
		<script src="../lib/soha.js" type="text/javascript"></script>
		<script type="text/javascript">
		var b = new Base64(); //加密
			// 生成当前时间
			var myDate = new Date();
        	var timedata = _dateFormat(myDate, 'yyyy-MM-dd');
        	var code = "";
        	var timer ;
        	var phone ;
        	var recommendcode ;
        	var x = 60;

            query = ''+GetQueryString("userid");
                   
            //判断是否从分享界面来的 ，是则自动在文本框添加推荐码
            if ( query != "null" ) {
            	accountid = parseInt(b.decode(query)); //解密urlid
            	$('#fphone').val(accountid);
            }

            function invokeSettime(obj){
                var countdown=60;
                settime(obj);
                function settime(obj) {
                    if (countdown == 0) {
                        $(obj).attr("disabled",false);
                        $(obj).val("获取验证码");
                        countdown = 60;
                        return;
                    } else {
                        $(obj).attr("disabled",true);
                        $(obj).val("(" + countdown + ") s 重新发送");
                        countdown--;
                    }
                    setTimeout(function() {
                                settime(obj) }
                            ,1000)
                }
            }

              

			
			// function getx(){

			// 	x = x-1;

			// 	$(".yanzhengma").text("重新发送("+x+")");
			// 	if(x == 0){
			// 		$(".yanzhengma").text("验证码");
			// 		$(".yanzhengma").on("click",function(){
			// 			x = 60;
			// 			getx();
						
			// 		});
			// 	}else{
			// 	 	timer = setTimeout("getx()",1000);
			// 	}
			// }

			$(".yanzhengma").click(function() {
				
			

				var shoujihao = $("#shoujihao").val();
				phone = shoujihao;
				if ( shoujihao == "" ) {
					alert("请输入手机号！");
					return ;
				}
				new invokeSettime(".yanzhengma");
				// $(this).off("click");
				// getx();
				// return ;
                               postJSON('/api/obtainaliyunsmsauthcode', {
					    		            "phone": shoujihao,
					    		            
					    		        }, function(result) {
					    		            code = result.msg;
					    		            console.log(code);
					    		        }, function(result) {
					    		            console.log("失败", result);
					    		        });
            });
            $(".go").click(function(){
            	          
            	var yanzhengma = $("#yanzhengma").val();//验证码
            	var codemd5 = hex_md5(yanzhengma);
            		
            	if (code != codemd5 ) {
            		alert("请填写正确的验证码！") ;
            		return ;
            	}

            	var password = $("#password").val();//密码
            	var password2 = $("#password2").val();//重复密码
            	
            	if(yanzhengma != ""){
            		if(password == password2 && password != ""){
					    var tel = $("#shoujihao").val();
					    if (tel != phone ) {
					    	alert("请填写正确的手机号码！");
					    	return ;
					    }
					    var dcode = yanzhengma;
					    var password = password;
					    var fphone = $("#fphone").val();
					    recommendcode = fphone ;
					    if (fphone.length == 11) {
					    	fid = 0 ;
					    }else{
					    	fid = fphone ;
					    	fphone = "" ; 
					    }
					     
            	       
					    				postJSON('/api/insertaccountheadhunters', {
					    		            "phone": tel,
					    		            "password": password,
					    		            "username": "",
					    		            "sex": "",
					    		            "age": 0,
					    		            "fphone": fphone,
					    		            "fid": parseInt(fid),
					    		            "wxopenid": "",
					    		            "time": timedata,
					    		        }, function(result) {
					    		        
					    		            if ( result.msg == "该手机号已被注册" ) {
					    		            	alert(result.msg)
					    		        		return ;
					    		        	}
					    		        	
					    		        	var thisid = '' + result.thisid ;
					    		        	
					    		        	var urlid = b.encode(thisid);

					    		        	
					    		            
					    		            postJSON('/api/insertgrade', {
					    		            	"accountid": parseInt(thisid),
						    		            "recommendcode": recommendcode,
						    		            "date": timedata,
					    		        }, function(result) {
					    		            alert("注册成功！");

					    		            window.location.href='HRzhuce2.html?id='+urlid;
					    		        }, function(result) {
					    		            console.log("失败", result);
					    		        });


					    		        }, function(result) {
					    		            console.log("失败", result);
					    		        });
					    	

	            	}else{
	            		alert("密码输入不一致");
	            	}
            	}else{
            		alert("请输入验证码");
            	}
            })
		</script>
	</body>
</html>
